<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Index extends Controller
{

    public function _initialize(){
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept,Authorization");
        header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE'); 
        
    }

    public function is_login(){
        $openid = session('weixin_user.openid');

        // dump($openid);exit;
        if(empty($openid)){
            return ['code'=>0,'msg'=>'未授权登录'];
        }else{
            $data = db('weixin_user')->where(['openid'=>$openid])->find();
            $data['nickname'] = base64_decode($data['nickname']);
            return $data;
        }
    }

    public function index(){
       
    }

    /**
     * 获取二维码并存入数据库
     */
    public function get_seconds()
    {
        $db = db('store');
        for ($i=1; $i < 32; $i++) {
            $ticket = urlencode($this->createSeconds($i,'action_name'));
            $url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.$ticket;
            $file =  "public/uploads/".$i.".jpg";
            $ch = curl_init($url);
            $fp = fopen($file, 'wb');
            curl_setopt($ch, CURLOPT_FILE, $fp);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_exec($ch);
            // curl_close($ch);
            fclose($fp);$fp = fopen($file, 'wb');
            curl_setopt($ch, CURLOPT_FILE, $fp);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_exec($ch);
            curl_close($ch);
            fclose($fp);
            $seconds_url = 'http://demo01.mjgxym.cn/zjjy/public/uploads/'.$i.'.jpg';
            $db->where(['id'=>$i])->update(['seconds_url'=>$seconds_url]);

            
        }
    }

    public function add()
    {
        $param = input('param.');
        $db = db('store');
        if((!empty($param['region']))&&(!empty($param['name']))&&(!empty($param['type']))&&(!empty($param['address']))){
            $id = $db->insertGetId($param);
            if($id){
                $ticket = urlencode($this->createSeconds($id,'action_name'));
                $url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.$ticket;
                $file =  "public/uploads/".$id.".jpg";
                $ch = curl_init($url);
                $fp = fopen($file, 'wb');
                curl_setopt($ch, CURLOPT_FILE, $fp);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_exec($ch);
                // curl_close($ch);
                fclose($fp);$fp = fopen($file, 'wb');
                curl_setopt($ch, CURLOPT_FILE, $fp);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_exec($ch);
                curl_close($ch);
                fclose($fp);
                $seconds_url = 'http://demo01.mjgxym.cn/zjjy/public/uploads/'.$id.'.jpg';
                $num = $db->where(['id'=>$id])->update(['seconds_url'=>$seconds_url]);
                if($num){
                    return $this->success('成功');
                }else{
                    return $this->error('失败');
                }
            }else{
                return $this->error('失败');
            }
        }else{
            return $this->error('请确保数据完整性');
        }
    }




  


    /**
    * =========获取微信用户详细信息=====================
    **/
    public function wechatLogin($my_redirect_url=''){
        //游戏支付
        $AppID='wxabe4898dd871b83c';
        $AppSecret ='0420b7f287ca5d733302e866cd218100';

        
        $param = input('param.'); 
        // $my_redirect_url = $param['my_redirect_url'];
        
        $my_redirect_url = 'http://demo01.mjgxym.cn/zjjy/zjjy/index.php/index/index/index';

        $callback  = 'http://demo01.mjgxym.cn/zjjy/zjjy/index.php/index/index/wechatCllBack';
          //url('index/index/wechatCllBack'); //回调地址
        // $callback  = 'http://client.rup-china.com/bd20180409/index.php/index/index/wechatCllBack';
         //微信登录
         //-------生成唯一随机串防CSRF攻击
        $state  = md5(uniqid(rand(), TRUE));
        $_SESSION["wx_state"]    =   $state; //存到SESSION snsapi_userinfo snsapi_base
        $callback = urlencode($callback);
        $wxurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$AppID."&redirect_uri=".$callback."&response_type=code&scope=snsapi_userinfo&state={$state}#wechat_redirect";
        header("Location: $wxurl");
        exit;

    }
        //微信登录回调函数
    public function wechatCllBack() {
        //游戏支付
        $AppID='wxabe4898dd871b83c';
        $AppSecret ='0420b7f287ca5d733302e866cd218100';
        

        // $my_redirect_url = input('param.my_redirect_url');
        // $my_redirect_url = 'http://client.rup-china.com/bd20180409/weixin/index.html';

        $url='https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$AppID.'&secret='.$AppSecret.'&code='.$_GET['code'].'&grant_type=authorization_code';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_URL, $url);
        $json =  curl_exec($ch);
        curl_close($ch);
        $arr=json_decode($json,1);
         //得到 access_token 与 openid
        

        $url='https://api.weixin.qq.com/sns/userinfo?access_token='.$arr['access_token'].'&openid='.$arr['openid'].'&lang=zh_CN';
        // dump($url);exit;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_URL, $url);
        $json =  curl_exec($ch);
        curl_close($ch);
        $arr=json_decode($json,1);

        header("content-type:text/html;charset=utf-8");         //设置编码
        
        $this->_login_handle($arr);


    }

    /**
     * 获取签名
     *
     */
    function getSignPackage() {
        
        //游戏支付
        $AppID='wxabe4898dd871b83c';
        $AppSecret ='0420b7f287ca5d733302e866cd218100';
        

        $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

        // $param = input('param.');
        // $url = $param['url'];
        // return $url;
        $jsapiTicket = $this->getJsApiTicket($AppID,$AppSecret);

        $timestamp = time();
        $nonceStr = $this->createNonceStr();

        // 这里参数的顺序要按照 key 值 ASCII 码升序排序
        $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
        $signature = sha1($string);

        $signPackage = array(
            "appId"     => $AppID,
            "nonceStr"  => $nonceStr,
            "timestamp" => $timestamp,
            "url"       => $url,
            "signature" => $signature,

        );
                return $signPackage;
    }

    function createNonceStr($length = 16) {
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $str = "";
        for ($i = 0; $i < $length; $i++) {
            $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        }
        return $str;
    }

    function getJsApiTicket($appid,$appsecret) {
        $accessToken = $this->getAccessToken($appid,$appsecret);
        $access_token = json_decode($accessToken);
        $access_token = $access_token->access_token;
        $jsapi_ticket_data = db('jsapi_ticket')->find();
        if(empty($jsapi_ticket_data)){
            $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$access_token";
            $res = json_decode($this->httpGet($url));
            $ticket = $res->ticket;
            db('jsapi_ticket')->insert(['jsapi_ticket'=>$ticket,'time'=>time()]);
        }else{
            $time = time()-$jsapi_ticket_data['time'];
            if($time>7100){
               $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$access_token";
                $res = json_decode($this->httpGet($url));
                $ticket = $res->ticket;
                db('jsapi_ticket')->where(['id'=>$jsapi_ticket_data['id']])->update(['jsapi_ticket'=>$ticket]); 

            }else{
                $ticket = $jsapi_ticket_data['jsapi_ticket'];
            }
        }

        $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$access_token";
        $res = json_decode($this->httpGet($url));
        $ticket = $res->ticket;
        return $ticket;
    }


    function getAccessToken($appid,$appsecret) {
        $access_token_data = db('access_token')->find();
        
        if(empty($access_token_data)){
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
            $res = json_decode($this->httpGet($url));
            $access_token = $res->access_token;
            db('access_token')->insert(['access_token'=>$access_token,'time'=>time()]);
            return json_encode(array("access_token"=>$access_token));
        }else{
            $time = time()-$access_token_data['time'];
            if($time>7100){
                $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
                $res = json_decode($this->httpGet($url));
                // dump($res);exit;
                $access_token = $res->access_token;
                db('access_token')->where(['id'=>$access_token_data['id']])->update(['access_token'=>$access_token,'time'=>time()]);
                return json_encode(array("access_token"=>$access_token));
            }else{
                $access_token = $access_token_data['access_token'];
                return json_encode(array("access_token"=>$access_token));
            }
        }
    }
    

    function httpGet($url) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 500);
        // 为保证第三方服务器与微信服务器之间数据传输的安全性，所有微信接口采用https方式调用，必须使用下面2行代码打开ssl安全校验。
        // 如果在部署过程中代码在此处验证失败，请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($curl, CURLOPT_URL, $url);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }

   


    private function _login_handle($user_info,$my_redirect_url='',$from=''){
        $user_oauth = Db('weixin_user')->where(array("openid"=>$user_info['openid']))->find();
        if(empty($user_oauth)){
            /*二【如果用户不存在】
            * @1添加该用户到users
            */
            $nickname = base64_encode($user_info['nickname']);
            $new_user_data = array(
                'openid' => $user_info['openid'],
                'nickname' => $nickname, //名称
                'sex' => $user_info['sex'],//性别
                'city' => $user_info['city'],//城市
                'province' => $user_info['province'],//省份
                'country' => $user_info['country'], //国家
                'headimgurl' => $user_info['headimgurl'],//头像
                'create_time' => date("Y-m-d H:i:s"),

            );
            

            Db('weixin_user')->insertGetId($new_user_data);

            
            // $new_user_data['id'] = Db('weixin_user')->insertGetId($new_user_data);
            $weixin_user_data = Db('weixin_user')->where('openid',$user_info['openid'])->find();
            
            $user_oauth = $weixin_user_data;
        }
        
        session('weixin_user',$user_oauth);

        $openid = session('weixin_user.openid');
        // dump($openid);exit;
        // return $this->view('index/index');
        // if(empty($my_redirect_url)){
        //     // $this->redirect(url('index'));
        // }else{
            $my_redirect_url = 'http://client.rup-china.com/yxzf/index.php/index/index/index';
            header("Location: $my_redirect_url");exit;
            
        // }
    }


    //生成带参数二维吗
    public function createSeconds($scene_id=1,$action_name='action_name'){
        //游戏支付
        $AppID='wxabe4898dd871b83c';
        $AppSecret ='0420b7f287ca5d733302e866cd218100';
        $access_token = json_decode($this->getAccessToken($AppID,$AppSecret),true);

        $url='https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.$access_token['access_token'];
        //action_name   二维码类型，QR_SCENE为临时的整型参数值，QR_STR_SCENE为临时的字符串参数值，QR_LIMIT_SCENE为永久的整型参数值，QR_LIMIT_STR_SCENE为永久的字符串参数值
        $data='{"expire_seconds": 2592000, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": '.$scene_id.'}}}';
        $return_content=json_decode( $this->doPostData($url,$data));
        
        // dump($return_content);exit;
        return $return_content->ticket;
        
        // dump($return_content->ticket);exit;

    }
    public function doPostData($url,$data){

        $time_out=10;
        $urlarr     = parse_url($url);
        $errno      = "";
        $errstr     = "";
        if($urlarr["scheme"] == "https")
        {
            $transports = "ssl://";
            $urlarr["port"] = "443";
        } else {
            $transports = "tcp://";
            $urlarr["port"] = "80";
        }
        $fp=@fsockopen($transports .$urlarr['host'],$urlarr['port'],$errno,$errstr,$time_out);
        if(!$fp)
        {
            $ret='*ERROR*:'.$errno.' '.$errstr;
            Mage::log($ret,null,'post_error.log');
            return  $ret;
        }
        else
        {
            $ret='';
            if ($urlarr["query"]!="")
                fputs($fp, "POST ".$urlarr["path"].'?'.$urlarr["query"]." HTTP/1.1\r\n");
            else
                fputs($fp, "POST ".$urlarr["path"]." HTTP/1.1\r\n");
            fputs($fp, "Host: ".$urlarr["host"]."\r\n");
            fputs($fp, "Content-type: Content-Type: application/json\r\n");
            fputs($fp, "Content-length: ".strlen($data)."\r\n");
            fputs($fp, "Connection: close\r\n\r\n");
            fputs($fp, $data . "\r\n\r\n");
            while(!feof($fp))
            {
                $ret=$ret.@fgets($fp, 1024);
            }
            fclose($fp);

            $arr=explode("\r\n\r\n",$ret);
            if ($arr[1]!="") return $arr[1];
            return $ret;
        }

    }

    /**
     * 响应微信发送的Token验证http://client.rup-china.com/yxzf/index.php/index/index/weixin
     */
    public function weixin()
    {
        $get = input('get.');
        $TOKEN = 'zjjy235017';
        
        // $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
        if(!empty($get["echostr"])){

            $signature = $get["signature"];
            $timestamp = $get["timestamp"];
            $nonce = $get["nonce"];
            $echostr = $get['echostr'];
            //将参数组成一维数组 
            $arr = [$TOKEN,$timestamp,$nonce];
            //对参数字典序排序
            sort($arr, SORT_STRING);
            //拼接成字符串  
            $str = implode($arr);
            //加密字符串成签名  
            $signeHash  = sha1($str);

            // $file_name = 'public/weixin.log';
            
            // $this->log_result($file_name,$signature);

            if($signeHash  == $signature){
                echo $echostr;exit;
                // return true;
            }else{
                return false;
            }
        }else{
            $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
            // dump($TOKEN);exit;
            // $log = var_export($postStr, true);
            // $logFile = './weixin.txt';
            // $fp = fopen($logFile, 'a');
            // fwrite($fp, $postStr . "\n");
            // fclose($fp);
            // $postStr = file_get_contents("php://input");
            $this->responseMsg($postStr);
            
        }
        
    }

    function  log_result($file='public/weixin.log',$word) {
        if(!file_exists($file)){
            mkdir($file);
        }
        $fp = fopen($file,"a");
        flock($fp, LOCK_EX) ;
        fwrite($fp,"执行日期：".strftime("%Y-%m-%d-%H：%M：%S",time())."\n".$word."\n\n");
        flock($fp, LOCK_UN);
        fclose($fp);
    }

    //提现通知推送模板信息    参数：发送给谁的openid,下线姓名，时间（参数自定）
   public function put_forward_Message($openid=null,$order=null,$money=null,$time=null) {
        $time=date('Y-m-d H:i:s');
        // $openid='oQPN51Wb59qemDAvv26h0vbzJx2k';
        // $customName=321;
        $AppID='wx82f480b41d206171';
        $AppSecret ='cf678cc842cd839475e0eaafe93c3a23';
        //获取全局token
        $access_token = json_decode($this->getAccessToken($AppID,$AppSecret),true);
        
        //模板信息请求地址
        $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$access_token['access_token'];
        //发送的模板信息(微信要求json格式，这里为数组（方便添加变量）格式，然后转为json)
        $data = [
            //发送给谁  openid
            "touser"=>$openid,
            //模板ID
            "template_id"=>"EiOTc9J1HSQ4mdB_94HJz7IaDfF5bC5uYi6ibjDISEU",
            //点击后跳转url
            "url"=>"http://client.rup-china.com/yxzf/index.php/index/index/index",
            "topcolor"=>"#FF0000",
            //参数
            'data'=>[
                // 'first'=>'尊敬的用户，已有用户成为您的下线，详情：',
                'first'=>[
                    "value"=>'尊敬的用户，您的提现订单已经生成',
                    "color"=>"#173177"
                ],
                'orderno'=>[//订单号
                    "value"=>$order,
                    "color"=>"#173177"
                ],
                'refundno'=>[//商品数量
                    "value"=>1,
                    "color"=>"#173177"
                ],
                'refundproduct'=>[//商品金额
                    "value"=>$money,
                    "color"=>"#173177"
                ],
                'remark'=>[
                    "value"=>'感谢您的支持,详情可点击当前通知查看',
                    "color"=>"#173177"
                ]
                // 'remark'=>'感谢您的支持，如有疑问，请于客服人员联系。'
                
            ]

        ];

         //将上面的数组数据转为json格式
        $post_data = urldecode(json_encode($data));
        // dump($post_data);exit;
        $postUrl = $url;
        $curlPost = $post_data;
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);//运行curl
        curl_close($ch);
        
        return $data;
    }


    /* 
    *获取文章列表 
    *type 素材的类型:图片（image）、视频（video）、语音 （voice）、图文（news） 
    *offset 从全部素材的该偏移位置开始返回，0表示从第一个素材 返回 
    *count 返回素材的数量，取值在1到20之间 
    */  
    public function get_article_list($type='news', $offset='0', $count='20', $access_token='')  
    {  
        //https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN 
        $AppID='wxabe4898dd871b83c';
        $AppSecret ='0420b7f287ca5d733302e866cd218100'; 
        $access_token = json_decode($this->getAccessToken($AppID,$AppSecret),true); 

        $url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=".$access_token['access_token'];  
        // $data = '{"type":"'.$type.'","offset":"'.$offset.'","count":"'.$count.'"}'; 
        $data = json_encode(['type'=>$type,'offset'=>0,'count'=>20]); 
        //返回的数据  
        $response = $this->get_response_post($url, $data);  
        //echo strip_tags($response);  
        $res = json_decode($response, true);
        dump($res);exit;  
        return $res;  
    } 

    public function get_response_post($url, $data)  
    {  
        $curl = curl_init($url);  
        curl_setopt($curl, CURLOPT_HEADER, 0);//过滤头部  
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//获取的信息以文件流的形式返回，而不是直接输出。  
        curl_setopt($curl,CURLOPT_POST,true); // post传输数据  
        curl_setopt($curl,CURLOPT_POSTFIELDS,$data);// post传输数据  
        $responseText = curl_exec($curl);  
        curl_close($curl);  
      
        return $responseText;  
    }

 


    




    

    /**
     * 获取微信返回的数据
     */
    public function responseMsg($postStr=''){
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
        $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : "";
        if (empty($postStr)){
            echo "";
            exit;
        }
        $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

        $fromUsername = $postObj->FromUserName;//用户openid
        $fromUsername = (string)$fromUsername;

        $toUsername = $postObj->ToUserName; //公众号id
        $toUsername = (string)$toUsername;

        $keyword = trim($postObj->Content);
        $keyword = (string)$keyword;

        $textTpl = "<xml>
                        <ToUserName><![CDATA[toUser]]></ToUserName>
                        <FromUserName><![CDATA[FromUser]]></FromUserName>
                        <CreateTime>123456789</CreateTime>
                        <MsgType><![CDATA[event]]></MsgType>
                        <Event><![CDATA[CLICK]]></Event>
                        <EventKey><![CDATA[EVENTKEY]]></EventKey>
                        </xml>";
        //获取事件类型
        $MsgType = $postObj->MsgType;
        $MsgType = (string)$MsgType;

        $event = $postObj->Event;
        $event = (string)$event;

        $EventKey = $postObj->EventKey;
        $EventKey = (string)$EventKey;

        if($MsgType == 'event'){
            
            if($event == 'subscribe'){//用户未关注时，进行关注后的事件推送
                $array = explode('_', $EventKey);
                $key = $array[1];
            }
            if($event == 'SCAN'){//用户已关注时的事件推送
                $key = $EventKey;
            }
            $data = db('seconds')->where(['openid'=>$fromUsername])->find();
            if(empty($data)){
                $id = db('seconds')->insertGetId(['openid'=>$fromUsername,'key'=>$key,'time'=>date('Y-m-d H:i:s'),'y'=>date('Y'),'m'=>date('m'),'d'=>date('d')]);
                if($id){
                    db('store')->where(['id'=>$key])->setInc('num');
                }
            }
        }


        // if($MsgType == 'event'){
        //     if($event == 'SCAN'){
                
        //         //添加合作者  每个用户同时只能作为一个推广者或合作人
        //         $data = db('collaborator')->where(['openid'=>$fromUsername])->find();
        //         $frist_data_openid = db('first_qrcode')->where(['scene_id'=>$EventKey])->value('openid');
        //         if($frist_data_openid !== $fromUsername){
        //             //自己不能做自己的合伙人
        //             if(empty($data)){
        //                 $first_openid = db('first_qrcode')->where(['scene_id'=>$EventKey])->value('openid');//推广者openID
        //                 $id = db('collaborator')->insertGetId(['openid'=>$fromUsername,'scene_id'=>$EventKey,'time'=>time(),'first_openid'=>$first_openid]);
        //                 //推送消息
        //                 $this->first_Message($frist_data_openid,$EventKey);
        //                 $content = "欢迎关注悦动棋牌:<a href='http://client.rup-china.com/yxzf/index.php/index/index/index'>点我进入</a>";
        //                 // $content = $id;
        //                 $resultStr =   " <xml>

        //                 <ToUserName><![CDATA[".$fromUsername."]]></ToUserName>
                        
        //                 <FromUserName><![CDATA[".$toUsername."]]></FromUserName>
                        
        //                 <CreateTime>".time()."</CreateTime>

        //                 <MsgType><![CDATA[text]]></MsgType>

        //                 <Content><![CDATA[".$content."]]></Content>

        //                 </xml>";
        //                 echo $resultStr;exit;
        //             }
        //         }
        //         $content = "欢迎关注悦动棋牌:<a href='http://client.rup-china.com/yxzf/index.php/index/index/index'>点我进入</a>";
        //         $resultStr =   " <xml>

        //         <ToUserName><![CDATA[".$fromUsername."]]></ToUserName>
                
        //         <FromUserName><![CDATA[".$toUsername."]]></FromUserName>
                
        //         <CreateTime>".time()."</CreateTime>

        //         <MsgType><![CDATA[text]]></MsgType>

        //         <Content><![CDATA[".$content."]]></Content>

        //         </xml>";
        //         echo $resultStr;exit;




                
        //     }
        // }


    }














}
